package com.atguigu.realtime.util;

import org.wltea.analyzer.core.IKSegmenter;
import org.wltea.analyzer.core.Lexeme;

import java.io.IOException;
import java.io.StringReader;
import java.util.Collection;
import java.util.HashSet;

/**
 * Created by GodRUI on 2021/7/5 17:54
 */
public class IKUtil {

    public static void main(String[] args) {
        System.out.println(analyzer("我爱打篮球"));
    }

    public static Collection<String> analyzer(String text) {

        Collection<String> result = new HashSet<>();

        IKSegmenter ikSegmenter = new IKSegmenter(new StringReader(text),true);

        try {
            Lexeme lexeme = ikSegmenter.next();
            while (null != lexeme){
                result.add(lexeme.getLexemeText());
                lexeme = ikSegmenter.next();
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
        return result;
    }
}
